// struct Element

template<typename T>
AManager<T>::Element::Element(T* _object, IArgs* _datas, bool _delete)
	: Object(_object), Datas(_datas), Delete(_delete)
{
}

template<typename T>
AManager<T>::Element::~Element()
{
}

// class AManager

template<typename T>
AManager<T>::AManager()
{
}

template<typename T>
AManager<T>::~AManager()
{
	typename Elements::iterator it = m_elements.begin();
	for (; it != m_elements.end(); ++it)
	{
		if (it->second.first != NULL)
			delete it->second.first;
	}
	m_elements.clear();
}

template<typename T>
void AManager<T>::Add(std::string const& _name, T* _element,
	typename AManager<T>::MngrFunc _func, IArgs* _datas)
{
	if (_element == NULL)
		return ;
	typename Elements::iterator it = m_elements.begin();
	for (; it != m_elements.end(); ++it)
		if (it->first.compare(_name) == 0)
			return ;
	Element* e = new Element(_element, _datas, false);
	m_elements[_name] = Pair(e, _func);//Pair(_element, _func);
}

template<typename T>
void AManager<T>::GetElements(std::list<T*>& _out)
{
	typename Elements::iterator it = m_elements.begin();
	for (; it != m_elements.end(); ++it)
		_out.push_back(it->second.first->Object);
}

template<typename T>
T* AManager<T>::operator[](std::string const& _name)
{
	typename Elements::iterator it = m_elements.begin();
	for (; it != m_elements.end(); ++it)
		if (it->first.compare(_name) == 0)
			return (m_elements[_name].second.first->Object);
	return (NULL);
}
